/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aluno;

import entities.Repository;
import entities.annotations.ActionDescriptor;
import entities.annotations.Param;
import entities.annotations.PropertyDescriptor;
import entities.annotations.View;
import entities.annotations.Views;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

/**
 *
 * @author pedro
 */
@Entity
@Views({
    @View(
        name="Frequencia",
        title="Frequencia diária",
        members = "[#aluno, realizarFrequencia()]",
        namedQuery = "select new aluno.FrequenciaDiaria()",
        template = "@PAGE"
        ),
    @View(
        name="FrequenciasRealizadas",
        title="Frequencias realizadas",
        header = "Ctrl.DAO.delete(),Ctrl.DAO.cancel()",
        members = "Ctrl.DAO.selectRow(),[*aluno.nomeCompleto; *aluno.matricula, presenca]",
        namedQuery = "From aluno.FrequenciaDiaria"
        
        )    
 })
public class FrequenciaDiaria implements Serializable{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
    
    @ManyToOne
    @NotNull
    private Aluno aluno;
    
    @PropertyDescriptor(displayName = "Data da presença")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date presenca = new Date();

    
    //@ActionDescriptor(value = "")
    public String realizarFrequencia(){
        Repository.save(this);
        return String.format("Frequencia realizada com sucesso!");
    }
    
    public Aluno getAluno() {
        return aluno;
    }

    public void setAluno(Aluno aluno) {
        this.aluno = aluno;
    }

    public Date getPresenca() {
        return presenca;
    }

    public void setPresenca(Date presenca) {
        this.presenca = presenca;
    }
    
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 11 * hash + (int) (this.id ^ (this.id >>> 32));
        hash = 11 * hash + (this.aluno != null ? this.aluno.hashCode() : 0);
        hash = 11 * hash + (this.presenca != null ? this.presenca.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final FrequenciaDiaria other = (FrequenciaDiaria) obj;
        if (this.id != other.id) {
            return false;
        }
        if (this.aluno != other.aluno && (this.aluno == null || !this.aluno.equals(other.aluno))) {
            return false;
        }
        if (this.presenca != other.presenca && (this.presenca == null || !this.presenca.equals(other.presenca))) {
            return false;
        }
        return true;
    }

    
    
}

